(function () {
    'use strict';

    angular.module('app')
        .factory('loadingFactory', [
            function () {
                var factory;
                factory = {
                    showLoading: function (elem, params) {
                        if (elem.find('.colorful-pulse').length > 0) {
                            return;
                        }
                        var id = 'colorfulPulse' + (params && params.type == 'color' ? 'Color' : 'Gray'),
                            $loadingHtml = $('<div id="' + id +'" class="colorful-pulse">\n' +
                                                '<span class="item-1"></span>\n' +
                                                '<span class="item-2"></span>\n' +
                                                '<span class="item-3"></span>\n' +
                                                '<span class="item-4"></span>\n' +
                                                '<span class="item-5"></span>\n' +
                                                '<span class="item-6"></span>\n' +
                                                '<span class="item-7"></span>\n' +
                                            '</div>');
                        elem.append($loadingHtml);
                    },
                    hideLoading: function (elem) {
                        elem.find('.colorful-pulse').remove();
                    }
                };
                return factory;
            }
        ]);
})();